package com.study.zzedu.ui.login;

import android.content.Context;
import android.os.Handler;

import com.study.zzedu.http.OnResultListener;
import com.study.zzedu.base.BasePresenter;
import com.study.zzedu.base.BaseView;


/**
 * Created by kiros on 2019/7/4.
 */

public class LoginPresenter extends BasePresenter<LoginContract.IView> {

    private LoginModel loginModel;

    public LoginPresenter() {
        this.loginModel = new LoginModel();
    }

    public void login(Context context, String username,String password, String code,String uuid,String deviceId) {

        loginModel.login(context,username, password, code,uuid,deviceId,new OnResultListener() {
            @Override
            public void onSuccess(String result) {
                getView().onLoginReturn(result);
            }

            @Override
            public void onError(String error) {
                getView().showError(error);
            }
        });
    }
    public void autoLogin(Context context, String username,String password,String deviceId) {

        loginModel.autoLogin(context,username, password,deviceId,new OnResultListener() {
            @Override
            public void onSuccess(String result) {
                getView().onLoginReturn(result);
            }

            @Override
            public void onError(String error) {
                getView().showError(error);
            }
        });
    }
    public void getImageCode(Context context) {

        loginModel.getImageCode(context,new OnResultListener() {
            @Override
            public void onSuccess(String result) {
                getView().onCodeReturn(result);
            }

            @Override
            public void onError(String error) {
                getView().onImageCodeError(error);
            }
        });
    }

    public void getLoginToken(Context context) {

        loginModel.getLoginToken(context,new OnResultListener() {
            @Override
            public void onSuccess(String result) {
                getView().onTokenReturn(result);
            }

            @Override
            public void onError(String error) {
                getView().showError(error);
            }
        });
    }
    public void getAutoLoginToken(Context context) {

        loginModel.getLoginToken(context,new OnResultListener() {
            @Override
            public void onSuccess(String result) {
                getView().onAutoTokenReturn(result);
            }

            @Override
            public void onError(String error) {
                getView().showError(error);
            }
        });
    }
}
